package org.marsdonne.demo4teiid_sb15;

import org.teiid.spring.annotations.InsertQuery;
import org.teiid.spring.annotations.SelectQuery;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "all_customers")
@SelectQuery("SELECT id, name, ssn FROM accountsDS.Customer "
        + "UNION "//UNION ALL
        + "SELECT id, name, ssn FROM customerDS.Customer")

@InsertQuery("FOR EACH ROW \n" +
        "BEGIN ATOMIC \n" +
        "INSERT INTO accountsDS.Customer(id, name, ssn) values (NEW.id, NEW.name, NEW.ssn);\n" +
        "INSERT INTO customerDS.Customer(id, name, ssn) values (NEW.id, NEW.name, NEW.ssn);\n" +
        "END")
public class Customer {
    @Id
    long id;
    @Column
    String name;
    @Column
    String ssn;

    public Customer() {
    }

    public Customer(int id, String name, String ssn) {
        this.id = id;
        this.name = name;
        this.ssn = ssn;
    }

    @Override
    public String toString() {
        return "Customer [id=" + id + ", name=" + name + ", ssn=" + ssn + "]";
    }
}
